<?php 
    require_once("qiniu/rs.php");
    
    $bucket = "facesbaby";
    $accessKey = "oI3AFn9pahuABAA68y_dX_kx5iFwuvKvPQPU4RIi";
    $secretKey = "1XadzqiEC94-4aL6KFu4Gh9MOL2hHb5g30PVHtlw";
    
    Qiniu_SetKeys($accessKey, $secretKey);
    $putPolicy = new Qiniu_RS_PutPolicy($bucket);
    //$putPolicy->ReturnUrl = "http://fbosc.cc/uploaded.php";
	$putPolicy->ReturnBody = "{\"state\": \"SUCCESS\", \"name\": $(fname),\"size\": \"$(fsize)\",\"w\": \"$(imageInfo.width)\",\"h\": \"$(imageInfo.height)\",\"key\":$(key),\"exif\":$(exif.DateTimeOriginal.val),\"baby_id\":\"".$_GET['babyid']."\"}";
    $upToken = $putPolicy->Token(null);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>相册 - 上传图片</title>
<script type="text/javascript">
    var $bucket = '<?php echo $bucket; ?>';
    var $upToken = '<?php echo $upToken;?>';
</script>

<link rel="stylesheet" href="Public/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="Public/css/homeindex.css">

  <!--[if lte IE 6]>
  <link rel="stylesheet" type="text/css" href="Public/bootstrap/css/bootstrap-ie6.css">
  <![endif]-->
  <!--[if lte IE 7]>
  <link rel="stylesheet" type="text/css" href="Public/bootstrap/css/ie.css">
  <![endif]-->
<link rel="stylesheet" href="swf/public/assets/css/default.css" />
<script type="text/javascript" src="swf/public/assets/js/jquery.js"></script>
<script type="text/javascript" src="swf/public/assets/js/utf8_encode.js"></script>
<script type="text/javascript" src="swf/public/assets/js/utf8_decode.js"></script>
<script type="text/javascript" src="swf/public/assets/js/base64_encode.js"></script>
<script type="text/javascript" src="swf/public/assets/js/base64_decode.js"></script>
<script type="text/javascript" src="swf/public/assets/js/uniqid.js"></script>
<script type="text/javascript" src="swf/public/assets/js/helper.js"></script>
<script type="text/javascript" src="swf/public/assets/swfupload/swfupload.js"></script>
<script type="text/javascript" src="swf/public/assets/js/swfupload.queue.js"></script>
<script type="text/javascript" src="swf/public/assets/js/fileprogress.js"></script>
<script type="text/javascript" src="Public/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="Public/artDialog/artDialog.source.js?skin=default" charset="utf-8"></script>

<script type="text/javascript">

var fb_labels = {$fb_labels};
var current_babyid = <?php echo $_SESSION['session_babyid'];?>;
var baby_json = <?php
echo json_encode($fb_baby_array['session_fb']);
?>;
var baby_focus_json = <?php
echo json_encode($baby_focus);
?>;
var baby_mine_json = <?php
echo json_encode($baby_mine);
?>;
</script>
<script type="text/javascript" src="swf/public/assets/js/focus_handler.js"></script>
<script type="text/javascript">
    var swfu;
//http://up.qbox.me/upload
    window.onload = function() {
        var settings = {
            flash_url : "swf/public/assets/swfupload/swfupload.swf",
            upload_url:  "http://up.qiniu.com/upload",
            post_params: {},
            use_query_string: false,
            file_post_name: "file",
            file_size_limit : "10 MB",
            file_types : "*.png;*.jpg;*.jpeg;*.gif",
            file_types_description: "Web Image Files",
            file_upload_limit : 100,
            file_queue_limit : 0,
            custom_settings : {
                fileUniqIdMapping : {},
                progressTarget : "fsUploadProgress",
                cancelButtonId : "btnCancel"
            },
            debug: false,

            // Button Settings
            button_image_url : "Public/img/myupload.png",
            button_placeholder_id : "uploadBtnHolder",
            button_width: 196,
                button_height: 143,
				button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				button_cursor: SWFUpload.CURSOR.HAND,

            // The event handler functions are defined in handlers.js
            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,
            queue_complete_handler : queueComplete	// Queue plugin event
	};

	swfu = new SWFUpload(settings);
    };
</script>
<style type="text/css">

.uploadHot{
	width:588px;
	height:182px;
	margin:0 auto;
	border:1px solid #ccc;	
	text-align:center;
	margin-top:20px;
	margin-bottom:20px;
}
.uploadHot:hover{
	background:url(Public/img/hover.png) repeat-x;
	background-position:0px -1px;
	border:1px solid #d3d3d3;	
}
.uploadHot .uploadIcon{
	margin:20px auto 0px;
	width:92px;
	height:81px;
	background:url(Public/img/upload.png);
	background-position:-49px -80px;	
}
.uploadHot .uploadBtn {
margin: 12px auto 0px;
width: 190px;
overflow:hidden;
}
.line_dot, .linedot, .hr {
background: url(Public/img/master.png) repeat-x 0 -736px;
height: 1px;
overflow: hidden;
}

.photoInfo{
margin: 5px;
padding: 4px;
overflow:hidden;	
}

.photoInfoBlock{
	overflow:hidden;
	border:1px solid red;
	background:#fff
}
.photoInfoBlock .photoLeft{
margin: 10px;
width: 430px;
float: left;
border-right: 1px solid #dadada;
display: inline;
}
.photoInfoBlock .photoRight{
	margin: 10px 10px 10px 0px;
float: left;
width: 260px;
display: inline;
}
.photoInfoEntry{
	margin-bottom:2px;	
}
	.photoInfoEntry label{
display: inline-block;
vertical-align: middle;
font-size: 14px;
padding: 0 5px;
width: 100px;
text-align: right;
font-family: 'microsoft yahei','微软雅黑','黑体';
}
.shortLabel label{
	width:60px;	
}
label{vertical-align:middle}
input.form_input {
width: 200px;
height: 20px;
line-height: 20px;
}
.photoChkbox{
	width:180px;
	overflow:hidden;
	display:inline-block;	
}
.photoChkbox label{
padding: 0;
width: 60px;
text-align: left;
font-size: 12px;
color: #333;
vertical-align:middle;
	}
</style>
<link rel="stylesheet" href="Public/css/page_manage.css">
</head>
<body>
<include file="./template/default/Public/header-logined.html" />


<div class="container">

<div class="con-header">
	<h2><i></i>
    上传相片
    </h2>
</div>

<div class="uploadHot" id="uploadHot">
	<div class="uploadBtn"><span id="uploadBtnHolder"></span></div>
</div>
            <input id="btnCancel" type="button" value="取消所有上传" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;display:none" />
</div>

</div>


<div class="container" style="margin-top:10px;">
	<div class="row" id="content">
    <div class="alert">上传相片，即表示您已同意FacesBaby上传服务条款，请勿上传违法相片!</div>
    <form id="form1" action="index.php?s=/Home/Albums/FocusPhotoSave" method="post" enctype="multipart/form-data">
        <div class="line_dot"></div>
        <div id="batch_set" style="display:none">
        	<label><input type="checkbox" id="batch_chk">批量修改</label>
            <div id="batch_options" style="display:none;">
            <div>
            <label>访问权限:</label>
            <select onChange="batch_set_option(this.options[this.selectedIndex].value)">
            	<option value="" selected>请选择</option>
            	<option value="f">对我关注的人公开</option><option value="o">公开(宝宝展示页)</option><option value="p">私人</option>
            </select>
            </div>
            <div id="option_group" style="display:none">
            <label>用户组:</label><div class="photoChkbox"><label><input type="checkbox" class="g_chk" value="rr" checked>亲人</label><label><input type="checkbox" class="g_chk" value="ff" checked>朋友</label></div>
            </div>
            </div><!--end batch_options-->
            
        </div>
        <div class="fieldset flash" id="fsUploadProgress">
        </div>
        <!--<div id="divStatus">0 Files Uploaded</div>-->
        

<div class="form-actions" id="form-actions" style="display:none">
  <button type="submit" class="btn btn-primary">提交</button>
</div>

    </form>
	</div>
</div>



<div>


</div>

<script type="text/javascript">
function set_group_chk(c,val){
	if(val=="check"){
		$(c).each(function(){ 
			$(this).attr('checked','true');
		});
	}else if(val=="uncheck"){
		$(c).each(function(){ 
			 $(this).removeAttr("checked");
		});	
	}
}
//设置访问权限
function set_group_option(val){
	$(".photo_role").each(function(){ 
			$(this).val(val);
		});
		if(val=="f"){
			set_group_chk('.groupchk','check');
			$('.roleGroup').show();	
		}
		if(val=="o"){
			set_group_chk('.groupchk','uncheck');
			$('.roleGroup').hide();
		}
		if(val=="p"){
			set_group_chk('.groupchk','uncheck');
			$('.roleGroup').hide();
		}
}
function batch_set_option(val){
	if(val=="f"){
		set_group_option(val);
		
		set_group_chk('.g_chk','check');
		$('#option_group').show();
	}
	if(val=="o"){
		set_group_option(val);
		
		set_group_chk('.g_chk','uncheck');
		$('#option_group').hide();
		
	}
	if(val=="p"){
		set_group_option(val);
		
		set_group_chk('.g_chk','uncheck');
		$('#option_group').hide();
	}
	
}
//

function chkCount(c,obj){
var chk_i=0;	
	$(c).each(function(){
		if($(this).attr("checked")){
			chk_i++;
		}
	});
	
	if(chk_i==0){
		alert('至少选择一项!');
		
		$(c).attr("checked",'true');
		if(obj.val()!=""){
			chkBatch('.groupchk_r','check');
			chkBatch('.groupchk_f','check');
		}
	}else{

		if(obj.val()=='rr'){
			if(obj.attr("checked")){
			chkBatch('.groupchk_r','check');
			}else{
				chkBatch('.groupchk_r','uncheck');
			}
		}
		if(obj.val()=='ff'){
			if(obj.attr("checked")){
			chkBatch('.groupchk_f','check');
			}else{
				chkBatch('.groupchk_f','uncheck');
			}
		}
		
	}
}
function chkBatch(c,action){
	$(c).each(function(){
		if(action=="check"){
			$(this).attr("checked",'true');
		}else if(action=="uncheck"){
			$(this).removeAttr("checked");
		}
	});
}
var dialog;
function labelDialog(fname,fid,id,photo_id){
	dialog = art.dialog({
		id:fid,
		title:fname,
		drag:true,
    	follow: document.getElementById(id),
		button:{
			name:'关闭'	
		}
	});
	// jQuery ajax   
	$.ajax({
		url: 'index.php?s=/Home/Label/index/fid/'+fid+'/id/'+id+'/photo_id/'+photo_id,
		success: function (data) {
			dialog.content(data);
			$(".labelText").click(function(){
					labelAdd("#label_"+fid,$(this).attr("id"),$(this).text(),photo_id);
});	
		},
		cache: false
	});

				
}
function labelAdd(obj,id,t,photo_id){
	//Dom id, 序,标签名称
	$(obj).append('<span class="label label-info">'+t+'<input type="hidden" name="photo_label['+photo_id+'][]" value="'+id+'"><a href="javascript:void(0)" class="close" data-dismiss="alert">&times;</a></span>');
		
}
function reloadLabel(fid,photo_id){
	$.ajax({
		url: 'index.php?s=/Home/Label/index/fid/'+fid+'/id/label_'+fid+'/photo_id/'+photo_id,
		success: function (data) {
			art.dialog.list[fid].content(data);
			$(".labelText").click(function(){
					labelAdd("#label_"+fid,$(this).attr("id"),$(this).text(),photo_id);
});	
		},
		cache: false
	});	
}
function postLabel(fid,photo_id){
	
	var labelName = '';
	labelName = $("#newLabel_"+fid).val();
	if($.trim(labelName)!=''){
		$.ajax(
		{
			type: "POST",
                    url: 'index.php?s=/Home/Label/doAdd/',
                    data: "newLabel="+labelName,
                    dataType: "text",
                    success:function(resp){
						
						
	$.ajax({
		url: 'index.php?s=/Home/Label/index/fid/'+fid+'/id/label_'+fid+'/photo_id/'+photo_id,
		success: function (data) {
			art.dialog.list[fid].content(data);
			$(".labelText").click(function(){
					labelAdd("#label_"+fid,$(this).attr("id"),$(this).text(),photo_id);
});	
		},
		cache: false
	});
	
	
	
	
					}
		}
		);	
	}
}


$(document).ready(function(){
	$("#batch_chk").click(function(){
		if($(this).attr('checked')){
			$('#batch_options').show();
		}else{
			$('#batch_options').hide();
		}
	});
	$(".g_chk").click(function(){
		chkCount('.g_chk',$(this));
	});
	
});
</script>
<style type="text/css">
span.label{
margin-left:10px	
}
</style>
<include file="./template/default/Public/footer-logined.html" />

</body>
</html>
